package com.qf.android.huihui.common;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * 防止滑动冲突
 * Created by 韩爽 on 2017/1/10.
 */

public class MyRecyclerview extends RecyclerView {
    int lastX=-1;
    int lastY=-1;
    public MyRecyclerview(Context context) {
        super(context);
    }

    public MyRecyclerview(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        int x= (int) ev.getRawX();
        int y= (int) ev.getRawY();
        int dealtX=0;
        int dealtY=0;
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                dealtX=0;
                dealtY=0;
                getParent().requestDisallowInterceptTouchEvent(true);
                break;
            case MotionEvent.ACTION_MOVE:
                dealtX += Math.abs(x-lastX);
                dealtY += Math.abs(y-lastY);
                if(dealtX<dealtY){
                    getParent().requestDisallowInterceptTouchEvent(true);
                }else {
                    getParent().requestDisallowInterceptTouchEvent(false);
                }
                lastX = x;
                lastY = y;
                break;
            case MotionEvent.ACTION_CANCEL:
                break;
            case MotionEvent.ACTION_UP:
                break;
        }
        return super.dispatchTouchEvent(ev);


    }
}
